var fs = require("fs");
var extend = require('node.extend');
var apiLoader = function(pageName, callback) {
    var commonPath = "public/api/common.js";
    var pagePath = "public/api/" + pageName + ".js";
    fs.readFile(commonPath, function(error, data) {
        var commonApi = {};
        if(!error) {
            commonApi = JSON.parse(data.toString());
        }
        fs.readFile(pagePath, function(error, data) {
            var pageApi = {};
            if(!error) {
                pageApi = JSON.parse(data.toString());
            }
            var destObject = extend(true, commonApi, pageApi);
            callback(destObject);
        });
    });
}
module.exports = apiLoader;